<template>
  <span v-if="statistic.toString().length <= statsMaxLength">{{
    statistic
  }}</span>
  <a-tooltip v-else>
    <template slot="title">
      {{ statistic }}
    </template>
    {{ getNum(statistic) }}
  </a-tooltip>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import Big from 'big.js'

@Component({})
export default class ScientificNotation extends Vue {
  @Prop({ default: 0 }) statistic: any
  private statsMaxLength: number = 5

  /**
   * 对统计指标的数据处理
   * 如果数据特别长返回科学记数法的数据
   * @param bignum 需要处理的数据
   */
  private getNum(bignum: number) {
    const result = new Big(bignum)
    return result.toExponential(2)
  }
}
</script>
